#!/usr/bin/perl
# edquota.pl
# Run by edquota to edit some user's quota
my (@edquotafile, $i, $u, $fs, $sb, $hb, $sf, $hf, $f);
my ( %dir2dev, @mountlist, $dv, @line);
#$no_acl_check++;
#$0 =~ /^(\S+)\//;
#chdir($1);
#require './quota-lib.pl';
$u = $ENV{'QUOTA_USER'};
$fs = $ENV{'QUOTA_FILESYS'};
$sb = $ENV{'QUOTA_SBLOCKS'};
$hb = $ENV{'QUOTA_HBLOCKS'};
$sf = $ENV{'QUOTA_SFILES'};
$hf = $ENV{'QUOTA_HFILES'};
$f = $ARGV[0];

unless($sb)
{
	$sb = 0;
}
unless($hb)
{
	$hb = 0;
}
unless($sf)
{
	$sf = 0;
}
unless($hf)
{
	$hf = 0;
}

my @edquotafile, $i;

open(FILE, $f);
@edquotafile = <FILE>;
close(FILE);

#open(MOUNTLIST, "/bin/mount|");
#@mountlist = <MOUNTLIST>;
#close(MOUNTLIST);

@mountlist = `mount 2>/dev/null`;

$i = 0;
while($i < @mountlist)
{
	@line = split(/\s+/, $mountlist[$i]);
	$dir2dev{$line[2]} = $line[0];
	$i++;
}
$dv = $dir2dev{$fs};

$i = 0;
while($i < @edquotafile)
{
	@line = split(/\s+/, $edquotafile[$i]);
	if($line[1] eq $dv)
	{
		$line[3] = $sb;
		$line[4] = $hb;
		$line[6] = $sf;
		$line[7] = $hf;
		$edquotafile[$i] = join(" ", @line);
		$edquotafile[$i] = $edquotafile[$i]."\n";
	}
	$i++;
}

open(FILE, "> $f");
print FILE @edquotafile;
close(FILE);

#$nqdata = &edit_quota_file($qdata, $fs, $sb, $hb, $sf, $hf);
#open(FILE, "> $f");
#print FILE $nqdata;
#close(FILE);

